//
//  CustomAlertView.m
//  LittleFoxlive
//
//  Created by awh on 2019/5/27.
//  Copyright © 2019年 wh. All rights reserved.
//

#import "CustomAlertView.h"

@implementation CustomAlertView

-(instancetype)initWithFrame:(CGRect)frame  withType:(NSString*)Type title:(NSString*)title
{
    
    if (self) {
        self=[super initWithFrame:frame];
        self.backgroundColor=[UIColor colorWithWhite:0 alpha:0.0];

//        if ([Type isEqualToString:@"1"]) {
        
            [self createUIWithType:Type title:title];
//        }else
//        {
//            //弹窗
//
//        }
        
    }
    
    return self;
}
-(void)createUIWithType:(NSString*)type title:(NSString*)title
{
    
    _hideView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    _hideView.backgroundColor= [UIColor blackColor];
    _hideView.alpha=0.4;
    [self addSubview:self.hideView];
    
    _backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0 ,self.width-240*SCALAE, 480*SCALAE)];
    _backView.backgroundColor=[UIColor whiteColor];
    _backView.layer.masksToBounds=YES;
    _backView.center=self.center;
    _backView.layer.cornerRadius=10;
    _backView.userInteractionEnabled=YES;
    [self addSubview:self.backView];
    
    _TopTitleLbl=[[UILabel alloc]initWithFrame:CGRectMake(10*SCALAE,20*SCALAE, _backView.width-20*SCALAE, 30*SCALAE)];
    _TopTitleLbl.font=[UIFont boldSystemFontOfSize:16];
    _TopTitleLbl.textColor=KHEXCOLOR(@"#333333");
    _TopTitleLbl.textAlignment=1;
    _TopTitleLbl.text=@"验证申请：";
    [self.backView addSubview:self.TopTitleLbl];
    
    
    _titleLbl=[[UILabel alloc]initWithFrame:CGRectMake(30*SCALAE,_TopTitleLbl.bottom+30*SCALAE, _backView.width-60*SCALAE, 40*SCALAE)];
    _titleLbl.font=[UIFont systemFontOfSize:12];
    _titleLbl.textColor=KHEXCOLOR(@"#333333");
    _titleLbl.textAlignment=0;
    _titleLbl.text=@"你需要发送验证申请，等待对方通过：";
    [self.backView addSubview:self.titleLbl];
    
    
    _textTF=[[UITextField alloc]initWithFrame:CGRectMake(_titleLbl.x, _titleLbl.bottom+10*SCALAE, _titleLbl.width, 35)];
    _textTF.placeholder=@"验证申请...";
    _textTF.tintColor = KHEXCOLOR(@"333333");
    NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:_textTF.placeholder attributes:@{NSForegroundColorAttributeName : KHEXCOLOR(@"999999")}];
    _textTF.attributedPlaceholder = placeholderString;
    _textTF.tag=2;
    _textTF.textColor=KHEXCOLOR(@"333333");
    _textTF.font=[UIFont systemFontOfSize:14];
//    _textTF.layer.masksToBounds=YES;
//    _textTF.layer.cornerRadius=17.5;
    _textTF.layer.borderWidth=0.5;
    _textTF.layer.borderColor=KHEXCOLOR(@"#5291CC").CGColor;
    _textTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 0)];
    _textTF.leftViewMode = UITextFieldViewModeAlways;
    [self.backView addSubview:self.textTF];

    
    _remarktitleLbl=[[UILabel alloc]initWithFrame:CGRectMake(30*SCALAE,_textTF.bottom+30*SCALAE, _backView.width-60*SCALAE, 40*SCALAE)];
    _remarktitleLbl.font=[UIFont systemFontOfSize:12];
    _remarktitleLbl.textColor=KHEXCOLOR(@"#333333");
    _remarktitleLbl.textAlignment=0;
    _remarktitleLbl.text=@"为朋友设置备注：";
    [self.backView addSubview:self.remarktitleLbl];
    
    
    _remarkTF=[[UITextField alloc]initWithFrame:CGRectMake(_remarktitleLbl.x, _remarktitleLbl.bottom+10*SCALAE, _remarktitleLbl.width, 35)];
    _remarkTF.placeholder=@"备注...";
    _remarkTF.tintColor = KHEXCOLOR(@"333333");
    NSMutableAttributedString *placeholderString1 = [[NSMutableAttributedString alloc] initWithString:_remarkTF.placeholder attributes:@{NSForegroundColorAttributeName : KHEXCOLOR(@"999999")}];
    _remarkTF.attributedPlaceholder = placeholderString1;
    _remarkTF.textColor=KHEXCOLOR(@"333333");
    _remarkTF.font=[UIFont systemFontOfSize:14];
    _remarkTF.layer.borderWidth=0.5;
    _remarkTF.layer.borderColor=KHEXCOLOR(@"#5291CC").CGColor;
    _remarkTF.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 0)];
    _remarkTF.leftViewMode = UITextFieldViewModeAlways;
    [self.backView addSubview:self.remarkTF];
    
    if ([type isEqualToString:@"1"]) {
        
//        _titleLbl.text=@"验证申请：";
        _remarktitleLbl.hidden = _remarkTF.hidden = YES;
        _backView.frame = CGRectMake(0, 0 ,self.width-240*SCALAE, 300*SCALAE);
        _backView.center=self.center;
        
    }else if([type isEqualToString:@"2"])
    {
        _remarktitleLbl.hidden=YES;
        _remarkTF.hidden=YES;
        _backView.height=400*SCALAE;
        _titleLbl.y=_TopTitleLbl.bottom+70*SCALAE;
        _textTF.y= _titleLbl.bottom+10*SCALAE;
        
    }else if([type isEqualToString:@"3"])
    {
        _textTF.hidden=YES;
        _remarkTF.hidden=YES;
        _titleLbl.hidden=YES;
        _remarktitleLbl.hidden=YES;
        _backView.frame=CGRectMake(0, 0 ,self.width-120*SCALAE, 160);
        _backView.center=self.center;
        _TopTitleLbl.frame=CGRectMake(20, (_backView.height-85*SCALAE)/2-20, _backView.width-40, 60);
        _TopTitleLbl.font=[UIFont systemFontOfSize:16];
        _TopTitleLbl.textColor=KHEXCOLOR(kBlackColor);
//        _TopTitleLbl.text=@"删除并退出后，将不再接收此群聊的信息";
        _TopTitleLbl.numberOfLines = 0;
        _TopTitleLbl.text=title;


    }else if([type isEqualToString:@"4"])
    {
        _textTF.hidden=YES;
        _remarkTF.hidden=YES;
        _titleLbl.hidden=YES;
        _remarktitleLbl.hidden=YES;
        _backView.frame=CGRectMake(0, 0 ,self.width-120*SCALAE, 160);
        _backView.center=self.center;
        _TopTitleLbl.frame=CGRectMake(20, (_backView.height-85*SCALAE)/2-30, _backView.width-40, 60);
        _TopTitleLbl.font=[UIFont systemFontOfSize:16];
        _TopTitleLbl.textColor=KHEXCOLOR(kBlackColor);
        _TopTitleLbl.numberOfLines=0;
        _TopTitleLbl.text=@"删除好友后，将不再接收此好友的消息，\n并删除聊天记录";
    }else if ([type isEqualToString:@"5"])
    {
        _TopTitleLbl.text=@"禁言设置";
        _remarktitleLbl.hidden=YES;
        _remarkTF.hidden=YES;
        _titleLbl.text=@"请设置该用户的禁言时间";
        _titleLbl.frame=CGRectMake(30*SCALAE,_TopTitleLbl.bottom+40*SCALAE, _backView.width-60*SCALAE, 40*SCALAE);
        _textTF.frame=CGRectMake(_titleLbl.x, _titleLbl.bottom+10*SCALAE, _titleLbl.width, 35);
        _textTF.placeholder=@"请输入禁言时间,单位/分钟";
        if (@available(iOS 10.0, *)) {
            _textTF.keyboardType=UIKeyboardTypeASCIICapableNumberPad;
        } else {
            // Fallback on earlier versions
            _textTF.keyboardType=UIKeyboardTypeNumberPad;
        }
        
        CGFloat btnwidth= (_backView.width-210*SCALAE)/3;
        NSArray * titleArray=@[@"10分钟",@"60分钟",@"24小时"];
        for (int i=0; i<3; i++) {
            UIButton * btn =[UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame=CGRectMake(52.5*SCALAE+(btnwidth+52.5*SCALAE)*i, _textTF.bottom+50*SCALAE, btnwidth, 45*SCALAE);
            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
            btn .backgroundColor=KHEXCOLOR(kMainColor);
            btn.titleLabel.font=[UIFont systemFontOfSize:13];
            btn.tag=i+1;
            btn.layer.masksToBounds=YES;
            btn.layer.cornerRadius=5;
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(ClickBtnSelecdTime:) forControlEvents:UIControlEventTouchUpInside];
            [_backView addSubview:btn];
        }
    }else if ([type isEqualToString:@"6"])
    {
     
        _textTF.hidden=YES;
        _remarkTF.hidden=YES;
        _titleLbl.hidden=YES;
        _remarktitleLbl.hidden=YES;
        _backView.frame=CGRectMake(0, 0 ,self.width-120*SCALAE, 160);
        _backView.center=self.center;
        _TopTitleLbl.frame=CGRectMake(20, (_backView.height-85*SCALAE)/2-30, _backView.width-40, 60);
        _TopTitleLbl.font=[UIFont systemFontOfSize:16];
        _TopTitleLbl.textColor=KHEXCOLOR(kBlackColor);
        _TopTitleLbl.numberOfLines=0;
        _TopTitleLbl.text=@"拉黑好友后，将不再接收此好友的消息，\n并删除聊天记录";
    }else if ([type isEqualToString:@"7"]){
        _textTF.hidden=YES;
        _remarkTF.hidden=YES;
        _titleLbl.hidden=YES;
        _remarktitleLbl.hidden=YES;
        _backView.frame=CGRectMake(0, 0 ,self.width-120*SCALAE, 160);
        _backView.center=self.center;
        _TopTitleLbl.frame=CGRectMake(20, (_backView.height-85*SCALAE)/2-30, _backView.width-40, 60);
        _TopTitleLbl.font=[UIFont systemFontOfSize:16];
        _TopTitleLbl.textColor=KHEXCOLOR(kBlackColor);
        _TopTitleLbl.numberOfLines=0;
        _TopTitleLbl.text=title;
    }else if ([type isEqualToString:@"8"])
    {
        _titleLbl.hidden=YES;
        _remarkTF.hidden=YES;
        _remarktitleLbl.hidden=YES;
        
        _backView.frame=CGRectMake(0, 0, self.width-90, 150);
        _backView.center=self.center;
        
        _TopTitleLbl.frame=CGRectMake(10*SCALAE,35*SCALAE, _backView.width-20*SCALAE, 30*SCALAE);
        _TopTitleLbl.text=@"申请好友";
        _TopTitleLbl.font=[UIFont systemFontOfSize:15];
        _TopTitleLbl.textColor=KHEXCOLOR(@"#262B2F");
        

        NSString * text=[NSString stringWithFormat:@"你好，我是%@，很高兴认识你！",title];
        _textTF.hidden=NO;
        _textTF.frame=CGRectMake(17, _TopTitleLbl.bottom+30*SCALAE, _backView.width-34, 35);
        _textTF.placeholder=text;
        _textTF.backgroundColor=KHEXCOLOR(@"#F5F5F5");
        _textTF.layer.masksToBounds=YES;
        _textTF.layer.cornerRadius=4.5;
        _textTF.layer.borderWidth=0;
        
    }

    UIView*  lineV=[[UIView alloc]initWithFrame:CGRectMake(0,_backView.height-83*SCALAE,_backView.width, 0.5)];
    lineV.backgroundColor=KHEXCOLOR(IM_Color_SeparateLine);
    [self.backView addSubview:lineV];

    _cancelBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    _cancelBtn.frame=CGRectMake(5*SCALAE,_backView.height-80*SCALAE ,_backView.width/2-15*SCALAE , 75*SCALAE);
    [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [_cancelBtn setTitleColor:KHEXCOLOR(@"#333333") forState:UIControlStateNormal];
    _cancelBtn.titleLabel.font=[UIFont systemFontOfSize:16];
     _cancelBtn.tag=1;
    [_cancelBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.backView addSubview:self.cancelBtn];
    
    
    UIView*  lineV1=[[UIView alloc]initWithFrame:CGRectMake(_backView.width/2-0.25,lineV.bottom,0.5, 80*SCALAE)];
    lineV1.backgroundColor=KHEXCOLOR(IM_Color_SeparateLine);
    [self.backView addSubview:lineV1];
    
    
    _confirmBtn=[UIButton buttonWithType:UIButtonTypeCustom];
_confirmBtn.frame=CGRectMake(lineV1.right+5*SCALAE,_backView.height-80*SCALAE ,_backView.width/2-15*SCALAE , 75*SCALAE);
    if ([type isEqualToString:@"7"]) {
       [_confirmBtn setTitleColor:KHEXCOLOR(@"#4795EF") forState:UIControlStateNormal];
    }else{
      [_confirmBtn setTitleColor:KHEXCOLOR(@"333333") forState:UIControlStateNormal];
    }
    [_confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
   
    _confirmBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    _confirmBtn.tag=2;
    [_confirmBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.backView addSubview:self.confirmBtn];
    
    if ([type isEqualToString:@"3"]) {
        [_confirmBtn setTitleColor:KHEXCOLOR(@"#ED222F") forState:UIControlStateNormal];
    }else if ([type isEqualToString:@"8"])
    {
        [_confirmBtn setTitle:@"发送" forState:UIControlStateNormal];
        [_confirmBtn setTitleColor:KHEXCOLOR(@"#4795EF") forState:UIControlStateNormal];

    }
    if ([type isEqualToString:@"7"]) {
         _closerBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _closerBtn.frame=CGRectMake(self.backView.width-26,8 ,18 ,18);
          
        [_closerBtn setBackgroundImage:[UIImage imageNamed:@"弹窗的叉叉"] forState:UIControlStateNormal];
           
            _closerBtn.tag=133;
            [_closerBtn addTarget:self action:@selector(clickCloserButton:) forControlEvents:UIControlEventTouchUpInside];
            [self.backView addSubview:self.closerBtn];
    }
    
}

-(void)ClickBtnSelecdTime:(UIButton*)sender
{
    switch (sender.tag) {
        case 1:
            _textTF.text=@"10";
            break;
        case 2:
            _textTF.text=@"60";
            break;
        case 3:
            _textTF.text=@"1440";
            break;
        default:
            break;
    }
}
 -(void)clickButton:(UIButton*)sender
 {
    if (sender.tag==1) {
    
        if (self.clickBlock) {
            self.clickBlock(@"1",_textTF.text,_remarkTF.text);
        }
        
     }else
    {
        if (self.clickBlock) {
            if ([_textTF.text isEqualToString:@""]&&_textTF.text.length == 0) {
               self.clickBlock(@"2",_textTF.placeholder,_remarkTF.text);
            }else{
              self.clickBlock(@"2",_textTF.text,_remarkTF.text);
            }
            
        }
     }
 }

- (void)clickCloserButton:(UIButton *)sender{
    if (self.clickBlock) {
          self.clickBlock(@"133",_textTF.text,_remarkTF.text);
        }
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self endEditing:YES];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end







@implementation ShareView

-(instancetype)initWithFrame:(CGRect)frame  withType:(NSString*)Type
{
    
    if (self) {
        self=[super initWithFrame:frame];
        self.backgroundColor=[UIColor colorWithWhite:0 alpha:0.0];
        
        _hideView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
        _hideView.backgroundColor= [UIColor clearColor];
//        _hideView.alpha=0.6;
        [_hideView addTapCallBack:self sel:@selector(HideShareView)];
        [self addSubview:self.hideView];
        
        
//        _backView=[[UIView alloc]initWithFrame:CGRectMake(0,self.height-400*SCALAE-EMVIEWBOTTOMMARGIN,self.width, 400*SCALAE+EMVIEWBOTTOMMARGIN)];
        
        _backView=[[UIView alloc]initWithFrame:CGRectMake(0,self.height,self.width, 400*SCALAE+EMVIEWBOTTOMMARGIN)];
        _backView.backgroundColor=[UIColor whiteColor];
//        _backView.layer.masksToBounds=YES;
//        _backView.center=self.center;
//        _backView.layer.cornerRadius=10;
        _backView.userInteractionEnabled=YES;
        [self addSubview:self.backView];
        
        
        
        _TopTitleLbl=[[UILabel alloc]initWithFrame:CGRectMake(10*SCALAE,20*SCALAE, _backView.width-20*SCALAE, 30*SCALAE)];
        _TopTitleLbl.font=[UIFont boldSystemFontOfSize:16];
        _TopTitleLbl.textColor=KHEXCOLOR(@"#333333");
        _TopTitleLbl.textAlignment=1;
        _TopTitleLbl.text=@"分享给好友";
        [self.backView addSubview:self.TopTitleLbl];
        
        NSArray *arrTitle=@[@"QQ好友",@"微信好友",@"手机短信"];
        NSArray *imageArray=@[@"icon_share_qq110",@"icon_share_wx110",@"icon_duanxin"];

        CGFloat lblwidth=(SCREEN_WIDTH-140*SCALAE-390*SCALAE)/2;
        for (int i=0; i<3; i++) {
            UIButton *shareBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            if (i==0) {
                
                shareBtn.frame =CGRectMake(self.backView.width/2-50*SCALAE-100*SCALAE-115*SCALAE, CGRectGetMaxY(_TopTitleLbl.frame)+65*SCALAE, 100*SCALAE, 100*SCALAE);
            }else if(i==1)
                
            {
                shareBtn.frame =CGRectMake(self.backView.width/2-50*SCALAE, CGRectGetMaxY(_TopTitleLbl.frame)+65*SCALAE, 100*SCALAE, 100*SCALAE);

            }else
            {
                shareBtn.frame =CGRectMake(self.backView.width/2+50*SCALAE+110*SCALAE, CGRectGetMaxY(_TopTitleLbl.frame)+65*SCALAE, 100*SCALAE, 100*SCALAE);

            }
     
            shareBtn.tag=i+50;
            [shareBtn setBackgroundImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
            [shareBtn addTarget:self action:@selector(shareBtnAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.backView  addSubview:shareBtn];
            
            UILabel * lbl  =[[UILabel alloc]initWithFrame:CGRectMake(70*SCALAE+(130*SCALAE+lblwidth+6*SCALAE)*i,CGRectGetMaxY(shareBtn.frame)+15*SCALAE ,130*SCALAE,28*SCALAE)];
            lbl.textAlignment=NSTextAlignmentCenter;
            lbl.text= arrTitle[i];
            if (i==0) {
                
                lbl.frame =CGRectMake(self.backView.width/2-195*SCALAE-80*SCALAE,CGRectGetMaxY(shareBtn.frame)+15*SCALAE ,130*SCALAE,28*SCALAE);
            }else if (i==1)
                
            {
                lbl.frame =CGRectMake(self.backView.width/2-65*SCALAE,CGRectGetMaxY(shareBtn.frame)+15*SCALAE ,130*SCALAE,28*SCALAE);
            }else
            {
                lbl.frame =CGRectMake(self.backView.width/2+65*SCALAE+80*SCALAE,CGRectGetMaxY(shareBtn.frame)+15*SCALAE ,130*SCALAE,28*SCALAE);

            }
            lbl.font=[UIFont systemFontOfSize:12];
//            lbl.backgroundColor=[UIColor redColor];
            lbl.textColor=[UIColor grayColor];
            [self.backView addSubview:lbl];
        }
        
        
        _cancelBtn= [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelBtn.frame=CGRectMake(0, self.backView.height-80*SCALAE-EMVIEWBOTTOMMARGIN, SCREEN_WIDTH, 80*SCALAE);
        [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //    noButton.backgroundColor= [UIColor colorWithRed:198.0f/255.0f green:21.0f/255.0f blue:35.0f/255.0f alpha:1.0f];
        _cancelBtn.backgroundColor=[UIColor whiteColor];
        _cancelBtn.alpha=0.6;
        _cancelBtn.titleLabel.font=[UIFont systemFontOfSize:28*SCALAE];
        [_cancelBtn addTarget:self action:@selector(HideShareView) forControlEvents:UIControlEventTouchUpInside];
        [self.backView addSubview:self.cancelBtn];
        
    }
    
    return self;
}
-(void)shareBtnAction:(UIButton*)sender
{
    if (sender.tag == 50) {
        if (self.shareClickBlock) {
            self.shareClickBlock(@"1", @"", @"");
        }
         
    }else if (sender.tag==51)
    {
        if (self.shareClickBlock) {
            self.shareClickBlock(@"2", @"", @"");
        }
    }else
    {
        if (self.shareClickBlock) {
            self.shareClickBlock(_mobileStr, @"", @"");
        }
    }
    
}
-(void)showShareViewWith:(NSString * )phoneNum
{
    //手机号
    _mobileStr=phoneNum;
    KWeakSelf;
    self.hidden=NO;
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.backView.frame=CGRectMake(0,self.height-400*SCALAE-EMVIEWBOTTOMMARGIN,self.width, 400*SCALAE+EMVIEWBOTTOMMARGIN);
        
    } completion:^(BOOL finished) {
        
    }];
    
}
-(void)HideShareView
{
    KWeakSelf;
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.backView.frame=CGRectMake(0,self.height,self.width, 400*SCALAE+EMVIEWBOTTOMMARGIN);
        
    } completion:^(BOOL finished) {
        
        self.hidden=YES;
        

    }];
    
}

@end
